home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2000 July / CD 3 / redhat-6.2.iso / RedHat / instimage / usr / lib / anaconda / textw / silo.py < prev    next >
Encoding:
Python Source  |  2000-03-08  |  7.4 KB  |  258 lines

  1. #import gettext
  2. import iutil
  3. from snack import *
  4. from textw.constants import *
  5. from translate import _
  6.  
  7. #cat = gettext.Catalog ("anaconda", "/usr/share/locale")
  8. #_ = cat.gettext
  9.  
  10. class SiloAppendWindow:
  11.  
  12.     def __call__(self, screen, todo):
  13.     t = TextboxReflowed(53,
  14.              _("A few systems will need to pass special options "
  15.                "to the kernel at boot time for the system to function "
  16.                "properly. If you need to pass boot options to the "
  17.                "kernel, enter them now. If you don't need any or "
  18.                "aren't sure, leave this blank."))
  19.  
  20.     entry = Entry(48, scroll = 1, returnExit = 1)
  21.  
  22.     if todo.silo.getAppend():
  23.         entry.set(todo.silo.getAppend())
  24.  
  25.     buttons = ButtonBar(screen, [(_("OK"), "ok"), (_("Skip"), "skip"),  
  26.                  (_("Back"), "back") ] )
  27.  
  28.     grid = GridForm(screen, _("SILO Configuration"), 1, 3)
  29.     grid.add(t, 0, 0)
  30.     grid.add(entry, 0, 1, padding = (0, 0, 0, 1))
  31.     grid.add(buttons, 0, 2, growx = 1)
  32.  
  33.         result = grid.runOnce ()
  34.         button = buttons.buttonPressed(result)
  35.         
  36.         if button == "back":
  37.             return INSTALL_BACK
  38.  
  39.     if button == "skip":
  40.         todo.skipLilo = 1
  41.             todo.silo.setDevice(None)
  42.     else:
  43.         todo.skipLilo = 0
  44.  
  45.     if entry.value():
  46.         todo.silo.setAppend(string.strip(entry.value()))
  47.     else:
  48.         todo.silo.setAppend(None)
  49.  
  50.     return INSTALL_OK
  51.  
  52. class SiloWindow:
  53.     def __call__(self, screen, todo):
  54.     (mount, dev, fstype, format, size) = todo.fstab.mountList()[0]
  55.     if mount != '/': return INSTALL_NOOP
  56.     if todo.skipLilo: return INSTALL_NOOP
  57.  
  58.     bootpart = todo.fstab.getBootDevice()
  59.     boothd = todo.silo.getMbrDevice(todo.fstab)
  60.  
  61.     format = "/dev/%-11s %s%*s" 
  62.     # FIXME: Should be Master Boot Records (MBR) in RAID1 case
  63.     str1 = _("Master Boot Record (MBR)")
  64.     str2 = _("First sector of boot partition")
  65.     str3 = _("Create PROM alias `linux'")
  66.     str4 = _("Set default PROM boot device")
  67.     len1 = len(str1) + 17
  68.     len2 = len(str2) + 17
  69.     len3 = len(str3)
  70.     len4 = len(str4) 
  71.     lenmax = max((len1, len2, len3, len4))
  72.     if todo.silo.getSiloMbrDefault(todo.fstab) == 'mbr':
  73.         dflt = 1
  74.     else:
  75.         dflt = 0
  76.     bootdisk = boothd
  77.     if bootpart[:2] == "md":
  78.         bootdisk = bootpart
  79.     rc1 = SingleRadioButton (format % (bootdisk, str1, lenmax - len1, ""), None, dflt )
  80.     rc2 = SingleRadioButton (format % (bootpart, str2, lenmax - len2, ""), rc1, 1 - dflt)
  81.     if bootpart[:2] == "md":
  82.         rc1.setFlags (FLAG_DISABLED, FLAGS_SET)
  83.         rc2.setFlags (FLAG_DISABLED, FLAGS_SET)
  84.  
  85.     bootdisk = bootpart
  86.     if bootpart[:2] == "md":
  87.         bootdisk = boothd
  88.     prompath = todo.silo.disk2PromPath(bootdisk)
  89.     if prompath and len(prompath) > 0 and todo.silo.hasAliases():
  90.         default = 1
  91.     else:
  92.         default = 0
  93.     linuxAlias = Checkbox ("%s%*s" % (str3, lenmax - len3, ""), default)
  94.     if not default:
  95.         linuxAlias.setFlags (FLAG_DISABLED, FLAGS_SET)
  96.     bootDevice = Checkbox ("%s%*s" % (str4, lenmax - len4, ""), 1)
  97.  
  98.     bb = ButtonBar (screen, ((_("OK"), "ok"), (_("Back"), "back")))
  99.  
  100.     g = GridForm (screen, _("SILO Configuration"), 1, 8)
  101.  
  102.     g.add (Label (_("Where do you want to install the bootloader?")), 0, 0)
  103.     g.add (rc1, 0, 1)
  104.     g.add (rc2, 0, 2, padding = (0, 0, 0, 1))
  105.     g.add (linuxAlias, 0, 3)
  106.     g.add (bootDevice, 0, 4, padding = (0, 0, 0, 1))
  107.     g.add (bb, 0, 5, growx = 1)
  108.  
  109.     result = g.runOnce()
  110.  
  111.     if rc1.selected():
  112.         todo.silo.setDevice("mbr")
  113.     else:
  114.         todo.silo.setDevice("partition")
  115.  
  116.     lAlias = linuxAlias.selected() != 0
  117.     bDevice = bootDevice.selected() != 0
  118.  
  119.     todo.silo.setPROM(lAlias, bDevice)
  120.  
  121.     rc = bb.buttonPressed (result)
  122.  
  123.     if rc == "back":
  124.         return INSTALL_BACK
  125.     return INSTALL_OK
  126.  
  127.  
  128. class SiloImagesWindow:
  129.     def editItem(self, screen, partition, itemLabel):
  130.     devLabel = Label(_("Device") + ":")
  131.     bootLabel = Label(_("Boot label") + ":")
  132.     device = Label("/dev/" + partition)
  133.     newLabel = Entry (20, scroll = 1, returnExit = 1, text = itemLabel)
  134.  
  135.     buttons = ButtonBar(screen, [_("Ok"), _("Clear"), _("Cancel")])
  136.  
  137.     subgrid = Grid(2, 2)
  138.     subgrid.setField(devLabel, 0, 0, anchorLeft = 1)
  139.     subgrid.setField(device, 1, 0, padding = (1, 0, 0, 0), anchorLeft = 1)
  140.     subgrid.setField(bootLabel, 0, 1, anchorLeft = 1)
  141.     subgrid.setField(newLabel, 1, 1, padding = (1, 0, 0, 0), anchorLeft = 1)
  142.  
  143.     g = GridForm(screen, _("Edit Boot Label"), 1, 2)
  144.     g.add(subgrid, 0, 0, padding = (0, 0, 0, 1))
  145.     g.add(buttons, 0, 1, growx = 1)
  146.  
  147.     result = ""
  148.     while (result != string.lower(_("Ok")) and result != newLabel):
  149.         result = g.run()
  150.         if (buttons.buttonPressed(result)):
  151.         result = buttons.buttonPressed(result)
  152.  
  153.         if (result == string.lower(_("Cancel"))):
  154.         screen.popWindow ()
  155.         return itemLabel
  156.         elif (result == string.lower(_("Clear"))):
  157.         newLabel.set("")
  158.  
  159.     screen.popWindow()
  160.  
  161.     return newLabel.value()
  162.  
  163.     def formatDevice(self, type, label, device, default):
  164.     if (type == 2):
  165.         type = "Linux extended"
  166.     elif (type == 6):
  167.         type = "UFS"
  168.     else:
  169.         type = "Other"
  170.  
  171.     if default == device:
  172.         default = '*'
  173.     else:
  174.         default = ""
  175.         
  176.     return "%-10s  %-25s %-7s %-10s" % ( "/dev/" + device, type, default, label)
  177.  
  178.     def __call__(self, screen, todo):
  179.     (images, default) = todo.silo.getSiloImages(todo.fstab)
  180.     if not images: return INSTALL_NOOP
  181.     if todo.skipLilo: return INSTALL_NOOP
  182.  
  183.     # the default item is kept as a label (which makes more sense for the
  184.     # user), but we want our listbox "indexed" by device, which so we keep
  185.     # the default item as a device
  186.     for (dev, (label, type)) in images.items():
  187.         if label == default:
  188.         default = dev
  189.         break
  190.  
  191.     sortedKeys = images.keys()
  192.     sortedKeys.sort()
  193.  
  194.     listboxLabel = Label("%-10s  %-25s %-7s %-10s" % 
  195.         ( _("Device"), _("Partition type"), _("Default"), _("Boot label")))
  196.     listbox = Listbox(5, scroll = 1, returnExit = 1)
  197.  
  198.     for n in sortedKeys:
  199.         (label, type) = images[n]
  200.         listbox.append(self.formatDevice(type, label, n, default), n)
  201.         if n == default:
  202.         listbox.setCurrent(n)
  203.  
  204.     buttons = ButtonBar(screen, [ (_("Ok"), "ok"), (_("Edit"), "edit"), 
  205.                       (_("Back"), "back") ] )
  206.  
  207.     text = TextboxReflowed(55, _("The boot manager Red Hat uses can boot other " 
  208.               "operating systems as well. You need to tell me " 
  209.               "what partitions you would like to be able to boot " 
  210.               "and what label you want to use for each of them."))
  211.  
  212.     title = _("SILO Configuration")
  213.     g = GridForm(screen, title, 1, 4)
  214.     g.add(text, 0, 0, anchorLeft = 1)
  215.     g.add(listboxLabel, 0, 1, padding = (0, 1, 0, 0), anchorLeft = 1)
  216.     g.add(listbox, 0, 2, padding = (0, 0, 0, 1), anchorLeft = 1)
  217.     g.add(buttons, 0, 3, growx = 1)
  218.     g.addHotKey("F2")
  219.  
  220.     result = None
  221.     while (result != "ok" and result != "back" and result != "F12"):
  222.         result = g.run()
  223.         if (buttons.buttonPressed(result)):
  224.         result = buttons.buttonPressed(result)
  225.  
  226.         if (result == string.lower(_("Edit")) or result == listbox):
  227.         item = listbox.current()
  228.         (label, type) = images[item]
  229.         label = self.editItem(screen, item, label)
  230.         images[item] = (label, type)
  231.         if (default == item and not label):
  232.             default = ""
  233.         listbox.replace(self.formatDevice(type, label, item, default), item)
  234.         listbox.setCurrent(item)
  235.         elif result == "F2":
  236.         item = listbox.current()
  237.         (label, type) = images[item]
  238.         if (label):
  239.             if (default):
  240.             (oldLabel, oldType) = images[default]
  241.             listbox.replace(self.formatDevice(oldType, oldLabel, default, 
  242.                     ""), default)
  243.             default = item
  244.             listbox.replace(self.formatDevice(type, label, item, default), 
  245.                     item)
  246.             listbox.setCurrent(item)
  247.  
  248.     screen.popWindow()
  249.  
  250.     if (result == "back"):
  251.         return INSTALL_BACK
  252.  
  253.     todo.silo.setSiloImages(images)
  254.     todo.silo.setDefault(label)
  255.  
  256.     return INSTALL_OK
  257.  
  258.